const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

/**
 * 文件上传
 * @param {文件} tempFilePaths 
 * @param {回调} callback 
 */
function upload(tempFilePaths,callback){
    let headerConfig = {
      'authorization': wx.getStorageSync("login_token") || '',
    }
    wx.uploadFile({
        url: 'http://yxcs.majiangyun.com/api/v1.common/upload',
        filePath: tempFilePaths,
        name: 'file',
        formData: {
            file: tempFilePaths,
            path: ''
        },
        header: headerConfig,
        success(res) {
            callback(res);
        },
        fail(e){
          console.log(e);
        }
    })
}

module.exports = {
  formatTime: formatTime,
  upload : upload
}
